package com.linqi.freebie.ui.main

import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.linqi.freebie.components.Control
import com.linqi.freebie.components.LogCat
import kotlinx.coroutines.launch

@Composable
fun MainScreen(
    snackbarHostState: SnackbarHostState,
    mainViewModel: MainViewModel = MainViewModel(),
    githubViewModel: GithubViewModel = GithubViewModel(),
    leftPanelRatio: Float = 0.3f
) {
    var appId by remember { mutableStateOf("") }
    val scope = rememberCoroutineScope()
    Row(modifier = Modifier.fillMaxSize()) {
        // 左侧控制面板
        Control(
            appId = appId,
            onAppIdChange = { appId = it },
            onStartClick = {
                if (appId.isNotBlank()) {
                    githubViewModel.loadData(appId = appId)
                } else {
                    scope.launch {
                        snackbarHostState.showSnackbar("APP_ID 不能为空")
                    }
                }
            },
            modifier = Modifier.weight(leftPanelRatio)
        )

        // 右侧分隔线
        VerticalDivider(modifier = Modifier.fillMaxHeight().width(1.dp))

        // 右侧内容区域
        LogCat(modifier = Modifier.weight(1 - leftPanelRatio))
    }
}